package com.sskj.mine.ui.activity;


import android.os.Bundle;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.just.agentweb.AgentWeb;
import com.sskj.common.base.App;
import com.sskj.common.util.LanguageUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.presenter.MineProtocalActivityPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;


@Route(path = RConfig.MINE_PROTOCAL)
public class MineProtocalActivity extends BaseActivity<MineProtocalActivityPresenter> {


    @BindView(R2.id.tvTitle)
    TextView tvTitle;
    @BindView(R2.id.left_img)
    ImageView leftImg;
    @BindView(R2.id.left_tv)
    TextView leftTv;
    @BindView(R2.id.ivBack)
    LinearLayout ivBack;
    @BindView(R2.id.right_tv)
    TextView rightTv;
    @BindView(R2.id.ivRight)
    ImageView ivRight;
    @BindView(R2.id.webView)
    WebView webView;
    AgentWeb mAgentWeb;
    @Autowired
    public String url;
    private String content;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_mine_protocal;
    }

    @Override
    public MineProtocalActivityPresenter getPresenter() {
        return new MineProtocalActivityPresenter();
    }

    @Override
    protected void initView() {
        super.initView();
        ARouter.getInstance().inject(this);
        tvTitle.setText(App.INSTANCE.getString(R.string.mine_mineProtocalActivity1_j));
        mAgentWeb = AgentWeb.with(this)
                .setAgentWebParent(webView, new LinearLayout.LayoutParams(-1, -1))
                .useDefaultIndicator()
                .createAgentWeb()
                .ready()
                .go("");
    }

    @Override
    protected void initData() {
        super.initData();
        String language = LanguageUtil.getAppLanguage(this);
        mPresenter.getContent(language);
    }

    public void updateUi(String content) {
        String CSS_STYLE = "<style>* {font-size:40px;line-height:60px;} p {color:#fff;} a {color:#fff;} img {width:100%;} pre {font-size:40pt;line-height:60pt;font-family:Courier New,Arial;border:1px solid #ddd;border-left:5px solid #fff;background:#fff;padding:5px;}</style>";
        content = content.replaceAll("<span.*?</span><span.*?</span>", "").replace("“", "").replace("”", "");
        content = "<body style=\"background:#D2DFDD;margin:0;padding-left:15px;padding-right:15px;margin-top:20px\">" + content + "</body" +
                ">";
        mAgentWeb.getUrlLoader().loadDataWithBaseURL(HttpConfig.BASE_URL, content, "text/html; charset=UTF-8", null, HttpConfig.BASE_URL);
    }
}
